package com.learn.grpc.hello;

import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;

@Slf4j
public class HelloServiceGrpcImpl extends com.learn.grpc.grpc.HelloServiceGrpc.HelloServiceImplBase {

    @Override
    public void ping(PingRequest request, StreamObserver<PingResponse> responseObserver) {

        String content = request.getContent();
        log.info("请求参数:" + content);

        PingResponse response = PingResponse.newBuilder()
                .setCode(0).setMessage("success")
                .setData(content + ":" + LocalDateTime.now())
                .build();

        // 向客户端写入数据
        responseObserver.onNext(response);
        // 通知客户端，写入完成
        responseObserver.onCompleted();
    }

}
